package com.fh.service.airsys.subsidylssue;

import java.text.DecimalFormat;
import java.util.List;

import javax.annotation.Resource;

import com.fh.dto.TranRequest;
import com.fh.service.airsys.airlineemployee.AirlineEmployeeService;
import com.fh.service.airsys.syscreditaccount.SysCreditAccountService;
import com.fh.service.airsys.transactiondetails.TransactionDetailsService;
import com.fh.service.transaction.OnLineTranService;
import com.fh.util.DateUtil;
import com.fh.util.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fh.dao.DaoSupport;
import com.fh.entity.Page;
import com.fh.util.PageData;


@Service("subsidylssueService")
public class SubsidyLssueService {

	@Resource(name = "daoSupport")
	private DaoSupport dao;
	@Autowired
	AirlineEmployeeService airlineEmployeeService;
	@Autowired
	SysCreditAccountService sysCreditAccountService;
	@Autowired
	TransactionDetailsService transactionDetailsService;
	@Autowired
	OnLineTranService onLineTranService;
	/*
	* 新增
	*/
	public void save(PageData pd)throws Exception{
		DecimalFormat format = new DecimalFormat("######0.00");
		PageData empData = airlineEmployeeService.findById(pd);
		pd.put("EI_CODE",empData.getString("EI_CODE"));
		pd.put("SA_ACC",empData.getString("SA_ACC"));
		pd.put("SD_STATE","1");
		pd.put("VERSION","0");
		pd.put("SA_ACC",empData.getString("SA_ACC"));
		Double amt = Double.valueOf(pd.getString("SD_AMOUNT"))*100;
		pd.put("SD_AMOUNT",amt);
		dao.save("SubsidyLssueMapper.save", pd);
		TranRequest request = new TranRequest();
		request.setTranType("1012");
		request.setEmpId(empData.getString("EI_EMINFO"));
		request.setTranAmt(amt.intValue());
		request.setOrgId(pd.getString("AL_CODE"));
		onLineTranService.tranExce(request);
		pd.put("VERSION","1");
		dao.update("SubsidyLssueMapper.edit", pd);
	}
	
	/*
	* 删除
	*/
	public void delete(PageData pd)throws Exception{
		dao.delete("SubsidyLssueMapper.delete", pd);
	}
	
	/*
	* 修改
	*/
	public void edit(PageData pd)throws Exception{
		dao.update("SubsidyLssueMapper.edit", pd);
	}
	
	/*
	*列表
	*/
	public List<PageData> list(Page page)throws Exception{
		List<PageData> list = (List<PageData>)dao.findForList("SubsidyLssueMapper.datalistPage", page);
		for (PageData pd:list){
			DecimalFormat format = new DecimalFormat("######0.00");
			Double amt = Double.valueOf((Integer)pd.get("SD_AMOUNT"))/100;
			pd.put("SD_AMOUNT",format.format(amt));
		}
		return list;
	}
	
	/*
	*列表(全部)
	*/
	public List<PageData> listAll(PageData pd)throws Exception{
		return (List<PageData>)dao.findForList("SubsidyLssueMapper.listAll", pd);
	}
	
	/*
	* 通过id获取数据
	*/
	public PageData findById(PageData pd)throws Exception{
		return (PageData)dao.findForObject("SubsidyLssueMapper.findById", pd);
	}
	
	/*
	* 批量删除
	*/
	public void deleteAll(String[] ArrayDATA_IDS)throws Exception{
		dao.delete("SubsidyLssueMapper.deleteAll", ArrayDATA_IDS);
	}
	
}

